from __future__ import print_function

from flask import url_for,request
from flask_restful import Resource

from . import api
from . import Nao

@api.resource("/api/control/Autonomous/<int:nao_id>")
class autonomous(Resource):
    def get(self,nao_id):
        nao = Nao.get(nao_id)
        autonomousLifeProxy = nao.get_autonomousLifeProxy()
        state = request.values["state"]
        state = str(state)
        autonomousLifeProxy.setState(state)

@api.resource("/api/control/wakeUp/<int:nao_id>")
class wake_up(Resource):
    def get(self,nao_id):
        nao = Nao.get(nao_id)
        motionProxy = nao.get_motionProxy()
        motionProxy.wakeUp()

@api.resource("/api/control/rest/<int:nao_id>")
class rest(Resource):
    def get(self,nao_id):
        nao = Nao.get(nao_id)
        motionProxy = nao.get_motionProxy()
        motionProxy.rest()

@api.resource("/api/control/Led/<int:nao_id>")
class led(Resource):
    def get(self,nao_id):
        nao = Nao.get(nao_id)
        option = request.values["option"]
        lp = nao.get_LEDPorxy()
        if option == "off":
            lp.off("AllLeds")
        if option == "on":
            lp.on("AllLeds")

@api.resource("/api/control/goToPosture/<int:nao_id>")
class go_to_posture(Resource):
    def get(self,nao_id):
        nao = Nao.get(nao_id)
        postureProxy = nao.get_postureProxy()
        postureName = request.values["postureName"]
        postureName = str(postureName)
        postureProxy.goToPosture(postureName, 0.5)

@api.resource("/api/control/hand/<int:nao_id>")
class hand(Resource):
    def get(self,nao_id):
        nao = Nao.get(nao_id)
        motionProxy = nao.get_motionProxy()
        handName = request.values["handName"]
        handName = str(handName)
        option = request.values["option"]
        if option == "close":
            motionProxy.closeHand(handName)
        if option == "open":
            motionProxy.openHand(handName)
